#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll car, det;
ll n, V;
ll T;
ll d[100005];
ll v[100005];
ll a[100005];
ll x;
ll tmp;
ll ans1=0;
ll ans2=0;
int main () {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
//    freopen("detect3.in", "r", stdin);
    cin >> T;
    for(ll t=1; t<=T; t++) {
        x=0;
        ans1=0;
        ans2=0;
        cin >> car >> det >> n >> V;
        for(ll i=1; i<=car; i++) {
            cin >> d[i] >> v[i] >> a[i];
        }
        for(ll i=1; i<=det; i++) {
            cin >> tmp;
            x=((x<tmp)?tmp:x);
        }
        for(ll i=1; i<=car; i++) {
            if((v[i]>V)&&(d[i]<=x)) {
                ans1++;
            }
        }
        if(ans1==0) {
            ans2=det;
        }
        else {
            ans2=det-1;
        }
        cout << ans1 << " " << ans2 << endl;
    }
    return 0;
}
